/*-
 * Copyright (c) 2012-2013 Shang-Rong Cai. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $ MTBLAS TEST: tst_lv_1_scp.c    Rev. 0.0.8    2013-10-10T14:36+08:00 $
 */

#include <stdio.h>
#include <complex.h>
#include <time.h>

#include <cblas.h>

#include <tst_lv_a_com.h>

int test_swapf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_ff_t vx;
    vec_ff_t vy;
    vec_ff_t vz;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_copyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_swapf(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = stblas_nrm2f(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_ff_delete(&vz);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_copyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_swapf(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = mtblas_nrm2f(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_ff_delete(&vz);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    cblas_scopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_sswap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    buf_cf = cblas_snrm2(PROPER_VECTOR_RUN, vz.data, vz.step);
    ierr = vec_ff_delete(&vz);

    printf("swapf() -> cblas_sswap()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_ff_delete(&vx);
    ierr = vec_ff_delete(&vy);

    return ierr;
}


int test_swap(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_df_t vx;
    vec_df_t vy;
    vec_df_t vz;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    struct timespec tp_b;  /* Time of test begin */
    struct timespec tp_e;  /* Time of test end */

    double cst_st;
    double cst_mt;
    double cst_cf;

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_copy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    ierr = stblas_swap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_st = clock_difftime(&tp_b, &tp_e);
    ierr = stblas_nrm2(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_df_delete(&vz);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_copy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    ierr = mtblas_swap(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_mt = clock_difftime(&tp_b, &tp_e);
    ierr = mtblas_nrm2(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_df_delete(&vz);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    cblas_dcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    cblas_dswap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_cf = clock_difftime(&tp_b, &tp_e);
    buf_cf = cblas_dnrm2(PROPER_VECTOR_RUN, vz.data, vz.step);
    ierr = vec_df_delete(&vz);

    printf("swap() -> cblas_dswap()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    printf("Time Cost: %10.6lf, %10.6lf, %10.6lf\n", cst_st, cst_mt, cst_cf);

    ierr = vec_df_delete(&vx);
    ierr = vec_df_delete(&vy);

    return ierr;
}


int test_swapl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_lf_t vx;
    vec_lf_t vy;
    vec_lf_t vz;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_copyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_swapl(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = stblas_nrm2l(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_lf_delete(&vz);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_copyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_swapl(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = mtblas_nrm2l(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_lf_delete(&vz);

    printf("swapl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lf_delete(&vx);
    ierr = vec_lf_delete(&vy);

    return ierr;
}


int test_cswapf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_fc_t vx;
    vec_fc_t vy;
    vec_fc_t vz;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_ccopyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cswapf(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = stblas_cnrm2f(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_fc_delete(&vz);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_ccopyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cswapf(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = mtblas_cnrm2f(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_fc_delete(&vz);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    cblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_cswap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    buf_cf = cblas_scnrm2(PROPER_VECTOR_RUN, vz.data, vz.step);
    ierr = vec_fc_delete(&vz);

    printf("cswapf() -> cblas_sswap()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_fc_delete(&vx);

    return ierr;
}


int test_cswap(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_dc_t vx;
    vec_dc_t vy;
    vec_dc_t vz;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cswap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = stblas_cnrm2(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_dc_delete(&vz);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_ccopy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cswap(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = mtblas_cnrm2(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_dc_delete(&vz);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    cblas_zcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_zswap(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    buf_cf = cblas_dznrm2(PROPER_VECTOR_RUN, vz.data, vz.step);
    ierr = vec_dc_delete(&vz);

    printf("cswap() -> cblas_dswap()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    ierr = vec_dc_delete(&vx);

    return ierr;
}


int test_cswapl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_lc_t vx;
    vec_lc_t vy;
    vec_lc_t vz;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);
    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = stblas_ccopyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cswapl(PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = stblas_cnrm2l(PROPER_VECTOR_RUN, vz.data, vz.step, &buf_st);
    ierr = vec_lc_delete(&vz);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vz);
    ierr = mtblas_ccopyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cswapl(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, vz.data, vz.step);
    ierr = mtblas_cnrm2l(thrz, PROPER_VECTOR_RUN, vz.data, vz.step, &buf_mt);
    ierr = vec_lc_delete(&vz);

    printf("cswapl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lc_delete(&vx);
    ierr = vec_lc_delete(&vy);

    return ierr;
}


int test_copyf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_ff_t vx;
    vec_ff_t vy;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_copyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_nrm2f(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_ff_delete(&vy);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_copyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_nrm2f(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_ff_delete(&vy);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_scopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_snrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_ff_delete(&vy);

    printf("copyf() -> cblas_scopy()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_ff_delete(&vx);

    return ierr;
}


int test_copy(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_df_t vx;
    vec_df_t vy;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    struct timespec tp_b;  /* Time of test begin */
    struct timespec tp_e;  /* Time of test end */

    double cst_st;
    double cst_mt;
    double cst_cf;

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    ierr = stblas_copy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_st = clock_difftime(&tp_b, &tp_e);
    ierr = stblas_nrm2(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_df_delete(&vy);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    ierr = mtblas_copy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_mt = clock_difftime(&tp_b, &tp_e);
    ierr = mtblas_nrm2(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_df_delete(&vy);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    clock_gettime(CLOCK_REALTIME, &tp_b);
    cblas_dcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    clock_gettime(CLOCK_REALTIME, &tp_e);
    cst_cf = clock_difftime(&tp_b, &tp_e);
    buf_cf = cblas_dnrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_df_delete(&vy);

    printf("copy() -> cblas_dcopy()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    printf("Time Cost: %10.3lf, %10.3lf, %10.3lf\n", cst_st, cst_mt, cst_cf);

    ierr = vec_df_delete(&vx);

    return ierr;
}


int test_copyl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_lf_t vx;
    vec_lf_t vy;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_copyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_nrm2l(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_lf_delete(&vy);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_copyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_nrm2l(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_lf_delete(&vy);

    printf("copyl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lf_delete(&vx);

    return ierr;
}


int test_ccopyf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_fc_t vx;
    vec_fc_t vy;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2f(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_fc_delete(&vy);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2f(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_fc_delete(&vy);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_scnrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_fc_delete(&vy);

    printf("ccopyf() -> cblas_ccopy()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_fc_delete(&vx);

    return ierr;
}


int test_ccopy(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_dc_t vx;
    vec_dc_t vy;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_dc_delete(&vy);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_dc_delete(&vy);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_zcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_dznrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_dc_delete(&vy);

    printf("ccopy() -> cblas_zcopy()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    ierr = vec_dc_delete(&vx);

    return ierr;
}


int test_ccopyl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    vec_lc_t vx;
    vec_lc_t vy;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2l(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_lc_delete(&vy);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2l(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_lc_delete(&vy);

    printf("ccopyl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lc_delete(&vx);

    return ierr;
}


int test_axpyf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    float alpha;
    vec_ff_t vx;
    vec_ff_t vy;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    alpha = -random_float();
    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_copyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_axpyf(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_nrm2f(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_ff_delete(&vy);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_copyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_axpyf(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_nrm2f(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_ff_delete(&vy);

    ierr = vec_ff_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_scopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_saxpy(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_snrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_ff_delete(&vy);

    printf("axpyf() -> cblas_saxpy()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_ff_delete(&vx);

    return ierr;
}


int test_axpy(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    double alpha;
    vec_df_t vx;
    vec_df_t vy;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    alpha = -random_double();
    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_copy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_axpy(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_nrm2(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_df_delete(&vy);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_copy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_axpy(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_nrm2(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_df_delete(&vy);

    ierr = vec_df_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_dcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_daxpy(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_dnrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_df_delete(&vy);

    printf("axpy() -> cblas_daxpy()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    ierr = vec_df_delete(&vx);

    return ierr;
}


int test_axpyl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    long double alpha;
    vec_lf_t vx;
    vec_lf_t vy;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    alpha = -random_long_double();
    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_copyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_axpyl(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_nrm2l(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_lf_delete(&vy);

    ierr = vec_lf_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_copyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_axpyl(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_nrm2l(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_lf_delete(&vy);

    printf("axpyl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lf_delete(&vx);

    return ierr;
}


int test_caxpyf(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    float complex alpha;
    vec_fc_t vx;
    vec_fc_t vy;

    float buf_st;  /* Single-thread return */
    float buf_mt;  /* Multi-threads return */
    float buf_cf;  /* cblas return */

    alpha = -random_float() * _Complex_I;
    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopyf(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_caxpyf(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2f(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_fc_delete(&vy);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopyf(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_caxpyf(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2f(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_fc_delete(&vy);

    ierr = vec_fc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_caxpy(PROPER_VECTOR_RUN, (void*) &alpha, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_scnrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_fc_delete(&vy);

    printf("caxpyf() -> cblas_caxpy()\n");
    check_value_ff_stdout("    ST:", buf_st);
    check_value_ff_stdout("    MT:", buf_mt);
    check_value_ff_stdout("    CF:", buf_cf);

    ierr = vec_fc_delete(&vx);

    return ierr;
}


int test_caxpy(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    double complex alpha;
    vec_dc_t vx;
    vec_dc_t vy;

    double buf_st;  /* Single-thread return */
    double buf_mt;  /* Multi-threads return */
    double buf_cf;  /* cblas return */

    alpha = -random_double() * _Complex_I;
    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_caxpy(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_dc_delete(&vy);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopy(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_caxpy(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_dc_delete(&vy);

    ierr = vec_dc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    cblas_zcopy(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    cblas_zaxpy(PROPER_VECTOR_RUN, (void*) &alpha, vx.data, vx.step, vy.data, vy.step);
    buf_cf = cblas_dznrm2(PROPER_VECTOR_RUN, vy.data, vy.step);
    ierr = vec_dc_delete(&vy);

    printf("caxpy() -> cblas_zaxpy()\n");
    check_value_df_stdout("    ST:", buf_st);
    check_value_df_stdout("    MT:", buf_mt);
    check_value_df_stdout("    CF:", buf_cf);

    ierr = vec_dc_delete(&vx);

    return ierr;
}


int test_caxpyl(size_t thrz)
{
    int ierr = ERRNO_UNDEFINED;

    long double complex alpha;
    vec_lc_t vx;
    vec_lc_t vy;

    long double buf_st;  /* Single-thread return */
    long double buf_mt;  /* Multi-threads return */

    alpha = -random_long_double() * _Complex_I;
    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vx);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = stblas_ccopyl(PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_caxpyl(PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = stblas_cnrm2l(PROPER_VECTOR_RUN, vy.data, vy.step, &buf_st);
    ierr = vec_lc_delete(&vy);

    ierr = vec_lc_create(PROPER_VECTOR_MAX, PROPER_VECTOR_MIN, PROPER_VECTOR_RUN, &vy);
    ierr = mtblas_ccopyl(thrz, PROPER_VECTOR_RUN, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_caxpyl(thrz, PROPER_VECTOR_RUN, alpha, vx.data, vx.step, vy.data, vy.step);
    ierr = mtblas_cnrm2l(thrz, PROPER_VECTOR_RUN, vy.data, vy.step, &buf_mt);
    ierr = vec_lc_delete(&vy);

    printf("caxpyl()\n");
    check_value_lf_stdout("    ST:", buf_st);
    check_value_lf_stdout("    MT:", buf_mt);

    ierr = vec_lc_delete(&vx);

    return ierr;
}
